package de.hmm.hwip.connection.output;

import java.net.Socket;

import org.json.JSONObject;
import org.osgi.framework.BundleContext;

import android.content.Context;
import de.hmm.hwip.connection.api.IConOut;
/**
 *  Implementation of the Outgoing Connection Service.
 * 	Handles the outgoing Connection Messages
 * 	and searches for Gateway
 * 
 * @author johannes mendel
 * @version 26.09.2012
 *
 */
public class OutConImpl implements IConOut {
	
	/**
	 * starts a new Connection to send the data to other devices
	 * @param connection: Socket-Input received from other devices
	 * @param context: BundleContext from OSGi
	 * @param data: JSONObject with data
	 * @param securityFlag: boolean if connection is crypted
	 */
	@Override
	public void startCon(Socket connection , BundleContext context, JSONObject data, boolean securityFlag) {
		OutConThread oct = new OutConThread(connection, data, securityFlag, context);
		Thread toct = new Thread(oct);
		toct.start();
	}

	/**
	 * starts a new Connection to send the data to other devices
	 * @param receiver: target receiver from other devices
	 * @param context: BundleContext from OSGi
	 * @param androidContext: Context from android service
	 * @param data: String with data
	 * @param securityFlag: boolean if connection is crypted
	 */
	@Override
	public void startCon(String receiver, BundleContext context, Context androidContext, JSONObject data, boolean securityFlag) {
		OutConThread oct = new OutConThread(receiver, data, androidContext, securityFlag, context);
		Thread toct = new Thread (oct);
		toct.start();

	}

	/**
	 * starts a new Connection with every receiver in targets field and sends given data
	 * @param targets: Receivers of data
	 * @param context: BundleContext from OSGi
	 * @param data: Information to send
	 * @param securityFlag: boolean if connection is crypted
	 */
	@Override
	public void startBurstCon(String[] targets, BundleContext context,	JSONObject data, boolean securityFlag) {
		OutConThread oct = new OutConThread(targets, data, context);
		Thread toct = new Thread(oct);
		toct.start();
		
	}

}
